package net.moonbiter.ebs.protocols.httpjava.client;

import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.ObjectOutputStream;
import java.io.OutputStream;

import org.apache.commons.httpclient.methods.RequestEntity;

public class SerializedObjectRequestEntity implements RequestEntity {
	private byte[] buf;

	public SerializedObjectRequestEntity(Object obj) throws IOException {
		ByteArrayOutputStream os = new ByteArrayOutputStream();
		ObjectOutputStream oos = new ObjectOutputStream(os);
		oos.writeObject(obj);
		buf = os.toByteArray();
	}

	public long getContentLength() {
		return buf.length;
	}

	public String getContentType() {
		return "application/x-java-serialized-object";
	}

	public boolean isRepeatable() {
		return true;
	}

	public void writeRequest(OutputStream os) throws IOException {
		os.write(buf);
	}

}
